/*
package org.example.util;


import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.PDPageContentStream.AppendMode;
import org.apache.pdfbox.pdmodel.PDResources;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDType0Font;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;


public class ShippingLabelGenerator {
    // 动态数据
    // 动态数据
    public static class ShippingData {
        private String customerName;
        private String customerPhone;
        private String customerAddress;
        private String senderName;
        private String senderPhone;
        private String senderAddress;
        private String orderNumber;
        private String pickUpPoint;
        private String trackingNumber;
        private String numberOfItems;
        private LocalDateTime orderTime;

        public ShippingData(String customerName, String customerPhone, String customerAddress,
                            String senderName, String senderPhone, String senderAddress,
                            String orderNumber, String pickUpPoint, String trackingNumber,
                            String numberOfItems, LocalDateTime orderTime) {
            this.customerName = customerName;
            this.customerPhone = customerPhone;
            this.customerAddress = customerAddress;
            this.senderName = senderName;
            this.senderPhone = senderPhone;
            this.senderAddress = senderAddress;
            this.orderNumber = orderNumber;
            this.pickUpPoint = pickUpPoint;
            this.trackingNumber = trackingNumber;
            this.numberOfItems = numberOfItems;
            this.orderTime = orderTime;
        }

        // Getter 方法
        public String getCustomerName() {
            return customerName;
        }

        public String getCustomerPhone() {
            return customerPhone;
        }

        public String getCustomerAddress() {
            return customerAddress;
        }

        public String getSenderName() {
            return senderName;
        }

        public String getSenderPhone() {
            return senderPhone;
        }

        public String getSenderAddress() {
            return senderAddress;
        }

        public String getOrderNumber() {
            return orderNumber;
        }

        public String getPickUpPoint() {
            return pickUpPoint;
        }

        public String getTrackingNumber() {
            return trackingNumber;
        }

        public String getNumberOfItems() {
            return numberOfItems;
        }

        public LocalDateTime getOrderTime() {
            return orderTime;
        }
    }

    public static void main(String[] args) throws IOException {
        // 示例动态数据
        ShippingData data = new ShippingData(
                "张*",
                "186****1000",
                "山西省运城市西建天茂城",
                "17乐生活",
                "0359-8755558",
                "山西省运城市涑水东街041号",
                "LSH 8888888888",
                "西建天茂城东二门京东超市",
                "0359AF-1008",
                "3",
                LocalDateTime.of(2024, 11, 9, 12, 12, 12)
        );

        // 生成 PDF 文件
        String outputPath = "shipping_label.pdf";
        PDDocument document = new PDDocument();
        PDPage page = new PDPage(new PDRectangle(131, 72)); // 页面大小为 131mm x 72mm
        document.addPage(page);

        try (PDPageContentStream contentStream = new PDPageContentStream(document, page, AppendMode.APPEND, true)) {
            // 设置字体和颜色
            PDResources resources = page.getResources();
            //PDType1Font font = PDType1Font.HELVETICA;
            PDType0Font font = PDType0Font.load(document, new File("C:\\Windows\\Fonts\\simhei.ttf"));
            PDType1Font boldFont = null;//PDType1Font.HELVETICA_BOLD;

            // 添加头部信息
            addHeader(contentStream, resources, font, boldFont, data);

            // 添加订单信息
            addOrderDetails(contentStream, resources, font, boldFont, data);

            // 添加二维码占位符
            addBarcode(contentStream, resources, font, data);

            // 添加收件人信息
            addCustomerInfo(contentStream, resources, font, boldFont, data);

            // 添加寄件人信息
            addSenderInfo(contentStream, resources, font, boldFont, data);

            // 添加物品信息
            addItemInfo(contentStream, resources, font, boldFont, data);

            // 添加页脚信息
            addFooter(contentStream, resources, font, boldFont, data);
        }

        // 保存 PDF 文件
        document.save(outputPath);
        document.close();

        System.out.println("发货单 PDF 生成成功，路径为: " + outputPath);
    }

    private static void addHeader(PDPageContentStream contentStream, PDResources resources, PDType0Font font, PDType1Font boldFont, ShippingData data) throws IOException {
        contentStream.setFont(font, 12);
        contentStream.setNonStrokingColor(Color.BLACK);

        // 添加头部信息
        contentStream.beginText();
        contentStream.newLineAtOffset(100, 60); // 客服热线偏右对齐
        contentStream.showText("17乐生活");
        contentStream.endText();

        contentStream.beginText();
        contentStream.newLineAtOffset(20, 45);
        contentStream.showText("客服热线  " + data.getSenderPhone());
        contentStream.newLineAtOffset(0, -10);
        contentStream.showText("已验视  " + data.getOrderTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        contentStream.endText();
    }

    private static void addOrderDetails(PDPageContentStream contentStream, PDResources resources, PDType0Font font, PDType1Font boldFont, ShippingData data) throws IOException {
        contentStream.setFont(font, 12);
        contentStream.setNonStrokingColor(Color.BLACK);

        // 添加订单信息
        contentStream.beginText();
        contentStream.newLineAtOffset(20, 20);
        contentStream.showText("运单号  " + data.getOrderNumber());
        contentStream.endText();
    }

    private static void addBarcode(PDPageContentStream contentStream, PDResources resources, PDType0Font font, ShippingData data) throws IOException {
        // 添加二维码占位符（实际场景中可以用图片或二维码库生成二维码）
        //contentStream.drawImage(loadImage("barcode.png"), 50, 50, 30, 30); // 预留位置
    }

    private static void addCustomerInfo(PDPageContentStream contentStream, PDResources resources, PDType0Font font, PDType1Font boldFont, ShippingData data) throws IOException {
        contentStream.setFont(font, 12);
        contentStream.setNonStrokingColor(Color.BLACK);

        // 添加收件人信息
        contentStream.beginText();
        contentStream.newLineAtOffset(20, 10);
        contentStream.showText("收");
        contentStream.endText();

        contentStream.setFont(font, 12);
        contentStream.setNonStrokingColor(Color.BLACK);

        contentStream.beginText();
        contentStream.newLineAtOffset(50, 10);
        contentStream.showText(data.getCustomerName());
        contentStream.newLineAtOffset(0, -10);
        contentStream.showText(data.getCustomerPhone());
        contentStream.newLineAtOffset(0, -10);
        contentStream.showText(data.getCustomerAddress());
        contentStream.endText();
    }

    private static void addSenderInfo(PDPageContentStream contentStream, PDResources resources, PDType0Font font, PDType1Font boldFont, ShippingData data) throws IOException {
        contentStream.setFont(font, 12);
        contentStream.setNonStrokingColor(Color.BLACK);

        // 添加寄件人信息
        contentStream.beginText();
        contentStream.newLineAtOffset(20, -10);
        contentStream.showText("寄");
        contentStream.endText();

        contentStream.setFont(font, 12);
        contentStream.setNonStrokingColor(Color.BLACK);

        contentStream.beginText();
        contentStream.newLineAtOffset(50, -10);
        contentStream.showText(data.getSenderName() + " " + data.getSenderPhone());
        contentStream.newLineAtOffset(0, -10);
        contentStream.showText(data.getSenderAddress());
        contentStream.endText();
    }

    private static void addItemInfo(PDPageContentStream contentStream, PDResources resources, PDType0Font font, PDType1Font boldFont, ShippingData data) throws IOException {
        contentStream.setFont(font, 16);
        contentStream.setNonStrokingColor(Color.BLACK);

        // 添加物品信息
        contentStream.beginText();
        contentStream.newLineAtOffset(90, -30);
        contentStream.showText(data.getNumberOfItems() + "件");
        contentStream.endText();
    }

    private static void addFooter(PDPageContentStream contentStream, PDResources resources, PDType0Font font, PDType1Font boldFont, ShippingData data) throws IOException {
        contentStream.setFont(font, 8);
        contentStream.setNonStrokingColor(Color.BLACK);

        // 添加页脚信息
        contentStream.beginText();
        contentStream.newLineAtOffset(10, -60);
        contentStream.showText("主板商城 每日惊喜不断!");
        contentStream.endText();

        contentStream.setFont(font, 8);
        contentStream.beginText();
        contentStream.newLineAtOffset(90, -60);
        contentStream.showText("已验视");
        contentStream.endText();
    }

    */
/*private static PDImageXObject loadImage(String imagePath) throws IOException {
        File imageFile = new File(imagePath);
        BufferedImage image = javax.imageio.ImageIO.read(imageFile);
        return PDImageXObject.createFromImage(new PDDocument(), image, 1);
    }*//*

}
*/
